import Dao.LoginDao;
import Dao.projectDao;
import pojo.Login;
import pojo.projects;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        LoginDao loginDao = new LoginDao();
        projectDao projectDao=new projectDao();
        for (;;)
        {
            System.out.println("——————学生选课系统——————");
            System.out.println("1.登陆 2.注册 3.结束程序");
            int choose=scanner.nextInt();
            if(choose==1)
            {
                String username,password;
                System.out.println("请输入用户名");
                username=scanner.next();
                System.out.println("请输入密码");
                password=scanner.next();
                if(loginDao.Login_verify(username,password)) {
                    if (loginDao.showUserByUsername(username).get(0).is_teacher()) {
                        System.out.println("登陆成功");
                        for (;;)
                        {
                            System.out.println("1.管理课程学生 2.退出登陆");
                            int choose2=scanner.nextInt();
                            if (choose2==1)
                            {
                                String projects = projectDao.getProjectById(1).get(0).getProjects();
                                System.out.println(projects);
                                for (int i=1;i<=loginDao.showUser().size();i++)
                                {
                                    if(loginDao.showUserById(i).get(0).getProject1().equals(""))
                                    {
                                        continue;
                                    }
                                    else {
                                        if (loginDao.showUserById(i).get(0).getProject1().equals(projects)) {
                                            System.out.println(loginDao.showUserById(i).get(0).getUserName());
                                        }
                                    }
                                }
                                projects = projectDao.getProjectById(2).get(0).getProjects();
                                System.out.println(projects);
                                for (int i=1;i<=loginDao.showUser().size();i++)
                                {
                                    if(loginDao.showUserById(i).get(0).getProject2().equals(""))
                                    {
                                        continue;
                                    }
                                    else {
                                        if (loginDao.showUserById(i).get(0).getProject2().equals(projects)) {
                                            System.out.println(loginDao.showUserById(i).get(0).getUserName());
                                        }
                                    }
                                }
                            }
                            else if(choose2==2){
                                break;
                            }
                        }
                    } else {
                        Login login = loginDao.showUserByUsername(username).get(0);
                        System.out.println("登陆成功");
                        for (; ; ) {
                            System.out.println("1.选课 \t 2.已选课程 \t 3.退出登陆");
                            int choose2 = scanner.nextInt();
                            if (choose2 == 1) {
                                System.out.println("请选择你要选择的课程");
                                System.out.println(projectDao.showProject().toString());
                                System.out.println("请选择你要学习的课程 按0返回");
                                int choose21 = scanner.nextInt();
                                projects projects = projectDao.getProjectById(choose21).get(0);
                                if (choose21 == 1) {
                                    loginDao.updateLogin(projects, username, projects.getId());

                                } else if (choose21 == 2) {
                                    loginDao.updateLogin(projects, username, projects.getId());
                                } else if (choose21 == 0) {
                                    continue;
                                }
                            } else if (choose2 == 2) {
                                if (!login.getProject1().equals("")) {
                                    System.out.println(login.getProject1());
                                }
                                if (!login.getProject2().equals("")) {
                                    System.out.println(login.getProject2());
                                }
                            }
                            if (choose2 == 3) {
                                break;
                            }
                        }

                    }
                }
                else
                {
                    System.out.println("用户名或密码错误");
                }

            }
            else if(choose==2)
            {
                System.out.println("注册页面");
                System.out.println("请输入登陆名");
                String username=scanner.next();
                System.out.println("请输入登陆密码");
                String password=scanner.next();
                Login login = new Login(username, password, false, "", "");
                loginDao.addUser(login);
            }
            else if(choose==3)
            {
                break;
            }
            else
            {
                System.out.println("您的输入有误 请重新输入");
                continue;
            }
        }
    }
}
